﻿
#region Copyright & License
// --------------------------
// Copyright 2008 Daniel Gray
// --------------------------
// This file is part of Kale.
//
// Kale is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Kale is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with Kale.  If not, see <http://www.gnu.org/licenses/>.
#endregion
#region File details
// --------------------------------------------------------
// Filename          : ArgumentElementCollection.cs
// Author            : Daniel Gray
// Created           : 28/04/2008
// --------------------------------------------------------
#endregion
            
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace Kale.Core.Configuration
{
   public class ArgumentElementCollection : ConfigurationElementCollection
   {
      /// <summary>
      /// Gets the type of the <see cref="T:System.Configuration.ConfigurationElementCollection"/>.
      /// </summary>
      /// <value></value>
      /// <returns>The <see cref="T:System.Configuration.ConfigurationElementCollectionType"/> of this collection.</returns>
      public override ConfigurationElementCollectionType CollectionType
      {
         get
         {
            return ConfigurationElementCollectionType.BasicMap;
         }
      }

      /// <summary>
      /// Gets the name used to identify this collection of elements in the configuration file when overridden in a derived class.
      /// </summary>
      /// <value></value>
      /// <returns>The name of the collection; otherwise, an empty string. The default is an empty string.</returns>
      protected override string ElementName
      {
         get
         {
            return "argument";
         }
      }

      /// <summary>
      /// When overridden in a derived class, creates a new <see cref="T:System.Configuration.ConfigurationElement"/>.
      /// </summary>
      /// <returns>
      /// A new <see cref="T:System.Configuration.ConfigurationElement"/>.
      /// </returns>
      protected override ConfigurationElement CreateNewElement()
      {
         return new ArgumentElement("DEFAULT", "DEFAULT");
      }

      /// <summary>
      /// Gets the element key for a specified configuration element when overridden in a derived class.
      /// </summary>
      /// <param name="element">The <see cref="T:System.Configuration.ConfigurationElement"/> to return the key for.</param>
      /// <returns>
      /// An <see cref="T:System.Object"/> that acts as the key for the specified <see cref="T:System.Configuration.ConfigurationElement"/>.
      /// </returns>
      protected override object GetElementKey(ConfigurationElement element)
      {
         return ((ArgumentElement)element).Name;
      }

      /// <summary>
      /// Gets the <see cref="Kale.Core.Configuration.ArgumentElement"/> at the specified index.
      /// </summary>
      /// <value></value>
      public ArgumentElement this[int index]
      {
         get { return (ArgumentElement)BaseGet(index); }
      }

      /// <summary>
      /// Gets a dictionary of the collections values keyed to the name.
      /// </summary>
      /// <returns></returns>
      public Dictionary<string, string> ToDictionary()
      {
         Dictionary<string, string> dictionary = new Dictionary<string, string>();

         foreach (ArgumentElement element in this)
         {
            dictionary.Add(element.Name, element.Value);
         }

         return dictionary;
      }
   }
}
